import pygame

class Block():
    def __init__(self, setting, row, col):
        super().__init__()
        self.screen = setting.screen
        self.row = row
        self.col = col
        self.setting = setting
        self.surf = pygame.Surface(self.setting.areasize)
        self.rect = self.surf.get_rect()
        self.live = 0
        self.age = 0

    def set_live(self, live):
        if live==0:
            self.age = 0
        else:
            self.age += 1
        self.live = live

    def place(self):
        return (self.row, self.col)

    def update(self):
        self.rect.left = self.setting.areasize[0] * self.col
        self.rect.top = self.setting.areasize[1] * self.row
        if self.live == 1:
            self.color = self.setting.lifecolor
        else:
            self.color = self.setting.diedcolor
        self.surf.fill(self.color)
        self.screen.blit(self.surf, self.rect)
